package cn.sdormitory.common;

import cn.sdormitory.common.utils.PageUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Getter;

import java.util.function.Function;

@Getter
public class PageForm<Form extends PageForm<Form, Entity>, Entity> extends BaseForm<Form,Entity> {
    private long page = 1;
    private long pageSize = 10;

    protected PageForm(){
    }

    public Form setPage(long page) {
        this.page = page;
        //noinspection unchecked
        return (Form) this;
    }

    public Form setPageSize(long pageSize) {
        this.pageSize = pageSize;
        //noinspection unchecked
        return (Form) this;
    }

    public Page<Entity> generatePage(){
        return new Page<>(page,pageSize);
    }

    public <R> IPage<R> convertPage(IPage<Entity> page, Function<Entity,R> beanConvert){
        return PageUtil.convertPage(page,beanConvert);
    }
}
